import * as actionTypes from './constans'
import { fromJS } from 'immutable'

const defaultState= fromJS({
    focused:false,
    mouseIn:false,
    list:[],
    page:1,
    totalPage:1
  });
  
  export default  (state = defaultState,action)=>{
    switch(action.type){
      case actionTypes.SEARCH_FOCUS:
        return state.set('focused',true);
      case actionTypes.SEARCH_BLUR:
        return state.set('focused',false);
      case actionTypes.CHANGE_LIST:
        const lists=fromJS(action.value); //改变数组的时候要先把数组设置为immutable数组
        return state.merge({
          list:lists,
          totalPage:action.totalPage
        });
      case actionTypes.MOUSE_ENTER:
        return state.set('mouseIn',true);
      case actionTypes.MOUSE_LEAVE:
        return state.set('mouseIn',false);
      case actionTypes.CHANGE_INFOLIST:
        return state.set('page',action.value);
      default:
        return state;
    }
  }